package com.utf999.qiangmanger.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.utf999.qiangmanger.dao.iface.IOrderTypeDefineDAO;
import com.utf999.qiangmanger.entity.orm.OrderTypeDefineEntity;
import com.utf999.qiangmanger.entity.orm.OrderTypeEntity;
import com.utf999.qiangmanger.exception.BizException;
import com.utf999.qiangmanger.exception.ResponseCode;
import com.utf999.qiangmanger.service.AbstractService;
import com.utf999.qiangmanger.service.iface.IOrderTypeDefineService;

/**
 * @author yinwenjie
 *
 */
@Component("OrderTypeDefineServiceImpl")
public class OrderTypeDefineServiceImpl extends AbstractService<OrderTypeDefineEntity, IOrderTypeDefineDAO> implements IOrderTypeDefineService {
	
	/**
	 * 
	 */
	@Autowired
	private IOrderTypeDefineDAO orderTypeDefineDAO;
	
	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.service.AbstractService#getBaseDAO()
	 */
	@Override
	protected IOrderTypeDefineDAO getBaseDAO() {
		return this.orderTypeDefineDAO;
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.service.iface.IOrderTypeDefineService#queryOrderTypeDefine(java.lang.String)
	 */
	@Override
	public List<OrderTypeDefineEntity> queryOrderTypeDefine(String ordertypeid) throws BizException {
		if(StringUtils.isEmpty(ordertypeid)) {
			throw new BizException("错误的参数信息，请检查！", ResponseCode.E501);
		}
		return this.orderTypeDefineDAO.queryOrderTypeDefine(ordertypeid);
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.service.iface.IOrderTypeDefineService#appendOrderTypeDefine(java.lang.String, java.lang.Integer, java.lang.Integer)
	 */
	@Override
	public void appendOrderTypeDefine(String ordertypeid, Integer durationChange, Integer integralChange) throws BizException {
		if(StringUtils.isEmpty(ordertypeid) 
			|| integralChange == null || durationChange == null) {
			throw new BizException("错误的参数信息，请检查！", ResponseCode.E501);
		}
		
		OrderTypeDefineEntity define = new OrderTypeDefineEntity();
		define.setCreateTime(new Date());
		define.setDurationChange(durationChange);
		define.setIntegralChange(integralChange);
		//对应的工单类型
		OrderTypeEntity type = new OrderTypeEntity();
		type.setUid(ordertypeid);
		define.setOrderType(type);
		
		this.insert(define);
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.service.iface.IOrderTypeDefineService#removeOrderTypeDefine(java.lang.String)
	 */
	@Override
	public void removeOrderTypeDefine(String defineid) throws BizException {
		if(StringUtils.isEmpty(defineid)) {
			throw new BizException("错误的参数信息，请检查！", ResponseCode.E501);
		}
		
		this.orderTypeDefineDAO.delete(defineid);
	}
}
